const { setLastError } = require("../utils/log_tool");
const { BaseCommand } = require("./base");

class SendEmailCommand extends BaseCommand {
    async execute() {
        const { SMTPClient, Message } = await import("emailjs");
        const client = new SMTPClient(this.selfData.client);
        const message = new Message(this.selfData.message);

        return new Promise((resolve) => {
            client.send(message, (err, msg) => {
                if (err) {
                    setLastError(err);
                    resolve();
                } else {
                    resolve(msg);
                }
            });
        });
    }
}

module.exports = {
    SendEmailCommand,
};
